home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 855 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: news.iag.net!news
  2. From: jatmon@iag.net (John R Buchan)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: gets() question
  5. Date: 9 Jan 1996 19:20:06 GMT
  6. Organization: Internet Access Group, Orlando, Florida
  7. Message-ID: <4cuf56$frd@news.iag.net>
  8. References: <4cosgf$rir@newsbf02.news.aol.com> <4cqkt8$1quo@news.gate.net>
  9. NNTP-Posting-Host: pm1-orl4.iag.net
  10. X-Newsreader: WinVN 0.99.7
  11.  
  12. In article <4cqkt8$1quo@news.gate.net>, bhutto@gate.net says...
  13. <snip>
  14. >>   char s[3][10];
  15. >>
  16. >>   printf ("Enter s[0]:  ");
  17. >>   gets (s[0]);
  18. >          ^^^^          
  19. >
  20. >Your compiler didn't generate an error? *s* is not an array of pointers to 
  21. >arrays of chars as in argv[]. Now I remember why I always like being 
  22. explicit. 
  23. >Try this:
  24. >
  25. >        fgets(&s[0][0],9,stdin);
  26. >
  27. >You can use a 2 dimensional char array, except that you have to be complete 
  28. >in your form and s[0] is not. Because fgets() (or gets() for that matter) is 
  29. >looking for an address, you need to oblige, hence the prefix of *&*. 
  30.  
  31. Unless someone's changed the rules very recently, his expression was quite
  32. legal, though the use of gets is generally undesirable. 
  33.  
  34. Check out K&R II A8.6.2 P217:
  35.  
  36. ".......Also,
  37.      static int x3d[3][5][7];
  38. declares a static three-dimensional array of integers, with rank 3x5x7. In
  39. complete detail, x3d is an array of three items; each item is an array of five
  40. items; each of the latter arrays is an array of seven integers.  Any of the
  41. expressions x3d, x3d[i], x3d[i][j], x3d[i][j][k] may reasonably appear in an
  42. expression. Teh first three have type "array", the last has type int.  More
  43. specifically, x3d[i][j] is an array of 7 integers, and x3d[i] is an array of
  44. 5 arrays of 7 integers."
  45.  
  46. So s[0] would be type "array of 10 chars".  By 7.1 this would decay to a 
  47. pointer to the first char in the array.
  48.  
  49. -- 
  50. John R Buchan           -:|:-     Looking for that elusive FAQ?  ftp to:
  51. jatmon@mail.iag.net     -:|:-     rtfm.mit.edu /pub/usenet-by-group/....
  52.  
  53.